{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9fc7c9b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Too many arguments!\n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/env python3    #标准注释，可以让文件直接再Unix/Linux/Mac上运行\n",
    "# -*- coding: utf-8 -*-   #表示py文件本身使用标准utf-8编号：\n",
    "\n",
    "'a test module'           #任何模块代码的第一个字符串都被视为模块的文档注释“\n",
    "\n",
    "__author__ = 'Michael Liao'  #表明作者，可以把上面几行的内容全部删除，但按标准办事肯定没错\n",
    "\n",
    "import sys                #导入sys模块，我们就有了变量sys指向该模块，利用sys可以访问对应模块的所有功能\n",
    "\n",
    "def test():\n",
    "    args = sys.argv       #sys模块中有一个argv变量，用list存储了命令行的所有参数，argv至少有一个元素，因为第一个参数永远是该py文件的名称\n",
    "    if len(args)== 1:\n",
    "        print('Hello, world!')\n",
    "    elif len(args) == 2:\n",
    "        print('Hello, %s!' % args[1])\n",
    "    else:\n",
    "        print('Too many arguments!')\n",
    "if __name__=='__main__': #如果我们在qi其他地方导入hello模块，if判断将失败，这种if测试可以让一个模块通过命令行运行测试\n",
    "    test()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6b1a08c",
   "metadata": {},
   "source": [
    "### 作用域"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4dff3b5",
   "metadata": {},
   "source": [
    "正常的函数和变量名是公开的，可以被直接引用。"
   ]
  },
  {
   "cell_type": "raw",
   "id": "4692026a",
   "metadata": {},
   "source": [
    "类似__xxx__是特殊变量，可以直接被引用，但是又特殊用途，比如__author__,__name__就是特殊变量"
   ]
  },
  {
   "cell_type": "raw",
   "id": "be276701",
   "metadata": {},
   "source": [
    "类似_xxx,__xxx这样的函数或者变量，就是非公开的，不应该被直接引用。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c011fe3",
   "metadata": {},
   "source": [
    "这里主要体现代码封装和抽象的方法，即：\n",
    "外部不需要引用的函数全部定义成private，只有外部需要定义的函数才定义为public."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c30cde4e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
